import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
 * 数组+链表实现哈希桶
 * key和value都是任意类型类型的版本
 * 每一个数组都存放这链表的头节点
 */
public class HashBucket<K, V> {
    static class Node<K, V> {
        private K key;
        private V value;
        private Node<K,V> next;

        public Node(K key, V value) {
            this.key = key;
            this.value = value;
        }
    }

    public Node<K,V>[] array = (Node<K,V>[])new Node[10];
    public int usedSize;
    private static final float DEFAULT_LOAD_FACTOR = 0.75f;

    public HashBucket() {
    }

    public void put(K key, V val) {
        Node<K, V> node = new Node<>(key, val);
        int hash = node.hashCode();
        //因为我们这里是泛型 所以不能够直接整除 所以泛型内使用的类必须要重写hashcode方法
        int index = hash % array.length;
        Node<K,V> cur = array[index];
        while (cur != null) {
            if(cur.key.equals(key)){
                cur.value = val;
                return;
            }
            cur = cur.next;
        }
        node.next = array[index];
        array[index] = node;
        usedSize++;
        //计算负载因子
        Set<Integer> set = new HashSet<>();
    }

}






































